package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Date;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import model.Database;
import model.Pallet;

/**
 * The class which shows the information of an selected Pallet.
 */
public class InformationPanel extends JPanel{

	private ILabel id;
	private ILabel orderId;
	private ILabel cookieName;
	private ILabel produced;
	private ILabel delivered;
	private ILabel isBlocked;
	private JPanel infoPanel;
	
	/**
	 *  Is the constructor which sets up the gui.
	 */
	public InformationPanel(){
		setLayout(new BorderLayout());
		infoPanel = new JPanel(new GridLayout(7,1));
		infoPanel.add(id = new ILabel("ID","Lacks ID."));
		infoPanel.add(orderId = new ILabel("Order ID","Hasn't been ordered."));
		infoPanel.add(cookieName = new ILabel("Cookie name","Lacks a given name."));
		infoPanel.add(produced = new ILabel("Produced","Not produced."));
		infoPanel.add(delivered = new ILabel("Delivered","Not delivered."));
		infoPanel.add(isBlocked = new ILabel("Is blocked"));
		add(infoPanel, BorderLayout.NORTH);
	}
	
	/**
	 * Fills up the panel with the information recieved from the specified Pallet.
	 * @param pallet is the Pallet which's information is to be shown.
	 */
	public void setInformation(Pallet pallet){
		id.setText(pallet.id);
		orderId.setText(pallet.orderId);
		cookieName.setText(pallet.cookieName);
		produced.setText(pallet.produced);
		delivered.setText(pallet.delivered);
		isBlocked.setText(pallet.isBlocked);
	}

	/**
	 * A JLabel which sets a prior message to all information.
	 */
	private class ILabel extends JLabel{
		
		private String id;
		private String alternative;
		
		/**
		 * Constructor.
		 * @param id is the text which is to be written prior to any text.
		 */
		public ILabel(String id){
			this(id,"");
		}
		/**
		 * Constructor.
		 * @param id is the text which is to be written prior to any text.
		 * @param alternative is the text which should be written if the given text is null.
		 */
		public ILabel(String id, String alternative){
			super();
			super.setText("");
			this.id = id;
			this.alternative = alternative;
		}
		/**
		 * sets the text to be the toString of the given object, else sets it to alternative if object is null.
		 * @param o is the object which's toString is to be written.
		 */
		public void setText(Object o){
			if(o==null){
				o = alternative;
			}
			this.setText(o.toString());
		}
		
		/**
		 * sets the text to be the toString of the given object, else sets it to alternative if object is null.
		 * @param text is what is to be written with the id prior to it, if text is null it will instead write the alternative.
		 */
		public void setText(String text){
			if(text==null){
				text=alternative;
			}
			super.setText(id+": "+text);
		}
	}
	
}
